package com.jzr.bedside.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jzr.bedside.db1.model.TAllergy;
import com.jzr.bedside.db1.service.TAllergyService;
import com.jzr.common.entity.vo.Result;
import com.jzr.common.util.U;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "过敏信息接口")
@RestController
@RequestMapping("/api/allergy")
public class AllergyController {
    @Autowired
    private TAllergyService allergyService;

    @ApiOperation(value = "获取过敏信息")
    @GetMapping("/get")
    public Result<List<TAllergy>> get(@ApiParam("过敏信息参数") TAllergy record){
        if(record == null){
            return Result.fail("参数不能为空");
        }
        if(U.isBlank(record.getPatientCode())){
            return Result.fail("patientCode不能为空");
        }
        QueryWrapper<TAllergy> qw = new QueryWrapper<>();
        qw.orderByAsc("dept_code","code");
        if(record != null){
            qw.eq(TAllergy.PatientCode_,record.getPatientCode());
        }
        List<TAllergy> list = allergyService.list(qw);
        return Result.success("成功",list,list==null ? 0:list.size());
    }

}
